package com.suning.sawp.service.impl.job;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.suning.sawp.constants.CacheKeyConstants;
import com.suning.sawp.intf.dao.PreChargeDaoService;
import com.suning.sawp.intf.job.PrechargeActJobService;
import com.suning.sawp.po.precharge.PrechargeActivity;
import com.suning.sawp.service.util.DateUtils;
import com.suning.sawp.service.util.RedisCacheUtils;

@Service("prechargeActJobService")
public class PrechargeActJobServiceImpl implements PrechargeActJobService{

    @Resource
    PreChargeDaoService preChargeDaoService;
    
    @Resource
    RedisCacheUtils cacheUtils;
    
    @Override
    public void offSalePrechargeAct() {
        PrechargeActivity act = new PrechargeActivity();
        act.setUnequalStatus(PrechargeActivity.promoStatusType.END);
        Integer endTime = Integer.valueOf(DateUtils.getDateStrByFormat(new Date(), DateUtils.YYYYMMDD_PATTERN));
        act.setPromoEndTime(endTime);
        List<PrechargeActivity> list = preChargeDaoService.queryAct(act);
        if(CollectionUtils.isNotEmpty(list)){
            preChargeDaoService.updateActStatusByEndTime(endTime);
        }
        cacheUtils.clearCacheData(CacheKeyConstants.PRECHARGE_ACT);
        cacheUtils.clearCacheData(CacheKeyConstants.UNEXPIRE_ACT_LIST);
    }

}
